<?php

use app\common\enum\DeliveryType as DeliveryTypeEnum;

?>
<style>
    .tpl-form-line-form input[type=text]{
        width: 30%;
        display: inline;
    }
</style>
<div class="row-content am-cf">
    <div class="row">
        <div class="am-u-sm-12 am-u-md-12 am-u-lg-12">
            <div class="widget am-cf">
                <form id="my-form" class="am-form tpl-form-line-form" method="post">
                    <div class="widget-body">
                        <fieldset>
                            <div class="widget-head am-cf">
                                <div class="widget-title am-fl">签到设置</div>
                            </div>
                            <div class="am-form-group">
                                <label class="am-u-sm-3 am-form-label form-require"> 签到开关 </label>
                                <div class="am-u-sm-9">
                                    <label class="am-radio-inline">
                                        <input type="radio" name="sign[is_open]" value="1" data-am-ucheck
                                            <?= intval($values['is_open']) === 1 ? 'checked' : '' ?>> 开启
                                    </label>
                                    <label class="am-radio-inline">
                                        <input type="radio" name="sign[is_open]" value="0" data-am-ucheck
                                            <?= intval($values['is_open']) === 0 ? 'checked' : '' ?>> 关闭
                                    </label>
                                </div>
                            </div>
                            <div class="am-form-group">
                                <label class="am-u-sm-3 am-form-label form-require"> 签到奖励数量 </label>
                                <div class="am-u-sm-9">
                                    <input type="text" class="tpl-form-input" name="sign[point]"
                                           value="<?= $values['point'] ?>">
                                </div>
                            </div>
                            <div class="am-form-group">
                                <label class="am-u-sm-3 am-form-label form-require"> 是否开启连续签到奖励 </label>
                                <div class="am-u-sm-9">
                                    <label class="am-radio-inline">
                                        <input type="radio" name="sign[is_lianxu]" value="10" data-am-ucheck
                                            <?= intval($values['is_lianxu']) === 10 ? 'checked' : '' ?>> 关闭
                                    </label>
                                    <label class="am-radio-inline">
                                        <input type="radio" name="sign[is_lianxu]" value="20" data-am-ucheck
                                            <?= intval($values['is_lianxu']) === 20 ? 'checked' : '' ?>> 开启
                                    </label>
                                </div>
                            </div>
                            <div class="am-form-group">
                                <label class="am-u-sm-3 am-form-label form-require"> </label>
                                <div class="am-u-sm-9">
                                    <div class="am-btn am-btn-xs am-btn-secondary" @click="add_rule">添加规则</div>
                                </div>
                            </div>
                            <div class="am-form-group" v-for="(item,index) in lianxu_rule" :key="index">
                                <label class="am-u-sm-3 am-form-label form-require"> </label>
                                <div class="am-u-sm-9">
                                   <div>
                                       <span>连续签到</span>
                                       <input type="text" class="tpl-form-input" v-model="lianxu_rule[index].day">天，
                                       <span>额外奖励</span>
                                       <input type="text" class="tpl-form-input" v-model="lianxu_rule[index].num">积分
                                       <a @click="delete_item(index)" href="javascript:;" class="item-delete tpl-table-black-operation-del" style="display: none" v-show="index > 0">
                                           <i class="am-icon-trash"></i>
                                       </a>
                                   </div>
                                </div>
                            </div>
                            <div class="am-form-group">
                                <div class="am-u-sm-9 am-u-sm-push-3 am-margin-top-lg">
                                    <button type="submit" class="j-submit am-btn am-btn-secondary">提交
                                    </button>
                                </div>
                            </div>
                        </fieldset>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>
<script src="assets/common/js/vue.min.js"></script>
<script>
    $(function () {
        var setting = {
            el: 'many-app',
            baseData: null,
        };
        function Sign(options){
            setting =  $.extend(true, {}, setting,options);
            this.initialize()
        }
        Sign.prototype = {
            appVue:null,
            initialize:function () {
                var lianxu_rule = []
                if (typeof setting.baseData !== 'undefined' && setting.baseData !== null) {
                    lianxu_rule = setting.baseData['lianxu_rule'];
                    console.log(lianxu_rule)
                }
                this.appVue = new Vue({
                    el: '#my-form',
                    data: {
                        lianxu_rule:lianxu_rule
                    },
                    methods:{
                        getData: function () {
                            return this.$data;
                        },
                        add_rule(){
                            this.lianxu_rule.push({
                                day:'',
                                num:''
                            })
                        },
                        delete_item(index){
                            this.lianxu_rule.splice(index,1)
                        }
                    },
                })
            }
        }
        // window.Fitness = Fitness
        // 注册商品多规格组件
        var specMany = new Sign({
            el: '#my-form',
            baseData:<?= json_encode($values,true);?>
        });
        /**
         * 表单验证提交
         * @type {*}
         */
        $('#my-form').superForm({
            buildData: function () {
                var specData = specMany.appVue.getData();
                return {
                    sign:{lianxu_rule:specData.lianxu_rule}
                };
            },
            // 自定义验证
            validation: function () {

            }
        });

    });
</script>
